function trainPage(p){
		$.ajax({
			url : "train/loadTrain.sls",
			type : "post",
			data : {"page":p},
			dataType : "json",
			success : function(result) {
				show(result);
			},
			error : function(){
				window.location.href="error.sls";
			}
		});
}

function show(result){

	$("#train_tbody").empty();
	if(result.status == 0){
		var trains = result.data;
		for(var i=0;i<trains.length;i++){
			var tId = trains[i].tId;
			var tCourse = trains[i].tCourse;
			var tCher = trains[i].tCher;
			var tStu = trains[i].tStu;
			var tPlace = trains[i].tPlace;
			var tDate = trains[i].tDate;
			var tTime = trains[i].tTime;
			var s = '<tr><td>'+tCourse+'</td><td>'+
			tCher+'</td>'+
			'<td>'+tStu+'</td>'+
			'<td>'+tPlace+'</td>'+
			'<td>'+tDate+'</td>'+
			'<td>'+tTime+'</td>'+
			'</tr>';
			
			var $tr = $(s);
			$tr.data("trainId",tId);
			$("#train_tbody").append($tr);
		}

		$.ajax({
			url : "train/trainPage.sls",
			type : "post",
			dataType : "json",
			success : function(result) {
				if(result.status == 0 ){
					var page = result.data.page;
					var total = result.data.total;
					var top ;
					var end ;
					var pageBody = "";
					if(page == 1){
						top = '<a>上一页</a>';
					} else {
						top = '<a href="javascript:trainPage('+(page-1)+');">上一页</a>';
					}
					if(page == total){
						end = '<a>下一页</a>';	
					} else {
						end = '<a href="javascript:trainPage('+(page+1)+');">下一页</a>';
					}
					var i=1;
					var m=3;
					if(page>1){
						i = page-1;
						m = page+1;
					}
					if(m>total){
						i--;
						m = total;
					}
					if(i==0){
						i=1;
					}
					for(i;i<=m;i++){
						if(i==page){
							pageBody+='<a href="javascript:trainPage('+i+');" style="font-weight:bold;color:#8d341f;">'+i+'</a>';
						} else {
							pageBody+='<a href="javascript:trainPage('+i+');">'+i+'</a>';
						}
					}
					var s = top+pageBody+end;									
					$("#train_page").html(s);
				}
			},
			error : function(){
				window.location.href="error.sls";
			}
		});
	}
	

}


function searchName(){
	var name =$("#search").val();
	$.ajax({
		url : "train/searchTrain.sls",
		type : "post",
		data : {"name":name},
		dataType : "json",
		success : function(result) {
				show(result);
		},
		error : function(){
			window.location.href="error.sls";
		}
	});
}





